Hi Forum,
I'm back... in the meantime I found something interesting:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=download-all-attachments
var downloadDocument:NotesDocument = database.getDocumentByUNID(context.getUrl().getParameter("documentUNID"));
var attachments:java.util.Vector = session.evaluate("@AttachmentNames", downloadDocument);
// If there are no attachments then STOP!
if (attachments == null || (attachments.size() == 1 && attachments.get(0).toString().trim().equals(""))) {
this.setRendered(true); // Show the XPage
return;
}
var externalContext:javax.faces.context.ExternalContext = facesContext.getExternalContext();
var response:javax.servlet.http.HttpServletResponse = externalContext.getResponse();
// Get the name of the zip file to be shown in download dialog box
var zipFileName = context.getUrl().getParameter("zipFileName");
if (zipFileName == null || zipFileName.equals("")) {
zipFileName = "AllAttachments.zip";
} else if (!zipFileName.toLowerCase().endsWith(".zip")) {
zipFileName = zipFileName + ".zip";
}
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);
var outStream:java.io.OutputStream = response.getOutputStream();
var zipOutStream:java.util.zip.ZipOutputStream = new java.util.zip.ZipOutputStream(outStream);
var embeddedObj:NotesEmbeddedObject = null;
var bufferInStream:java.io.BufferedInputStream = null;
// Loop through all the attachments
for (var i = 0; i < attachments.size(); i++) {
embeddedObj = downloadDocument.getAttachment(attachments.get(i).toString());
if (embeddedObj != null) {
bufferInStream = new java.io.BufferedInputStream(embeddedObj.getInputStream());
var bufferLength = bufferInStream.available();
var data = new byte[bufferLength];
bufferInStream.read(data, 0, bufferLength); // Read the attachment data
var entry:java.util.zip.ZipEntry = new java.util.zip.ZipEntry(embeddedObj.getName());
zipOutStream.putNextEntry(entry);
zipOutStream.write(data); // Write attachment into Zip
bufferInStream.close();
embeddedObj.recycle();
}
}
// I tried to add some code here to create the last file using a text stream and to add it to the zip, file htmlfile.html is created inside the zip, // but how can I had text content to that file...
// Could someone help me adding my sessionscope.htmlCode into the htmlfile.html. Thx
var entry:java.util.zip.ZipEntry = new java.util.zip.ZipEntry(htmlfile.html);
zipOutStream.putNextEntry(entry);
zipOutStream.write(
sessionscope.htmlCode); // Write attachment into Zip
downloadDocument.recycle();
zipOutStream.flush();
zipOutStream.close();
outStream.flush();
outStream.close();
facesContext.responseComplete();
I'm able to create a zip file containing all my attachment and to create my html file but I'm missing the content into my html file.
Thx in advance,
Chris